from typing import List


class Solution:
    ## 9宫格的值作为索引， 比直接使用Map来说更高效
    def isValidSudoku(self, board: List[List[str]]) -> bool:
        row_used = [[False for _ in range(len(board[0]))] for _ in  range(len(board))]
        col_used = [[False for _ in range(len(board[0]))] for _ in  range(len(board))]
        board_ised = [[False for _ in range(len(board[0]))] for _ in  range(len(board))]
        for row in range(len(board)):
            for col in range(len(board[0])):
                if board[row][col] ==".":
                    continue
                num = int(board[row][col])-1

                if (row_used[row][num]): return False
                else: row_used[row][num] = True
                if (col_used[col][num]):return False
                else: col_used[col][num] = True

                boxIndex = row//3 + (col//3)*3
                if (board_ised[boxIndex][num]):return False
                else: board_ised[boxIndex][num]=True
        return True